package CPreprocess;

sub pushSegment {
	my ($line, $lines) = @_;

	my @splitted = ($line =~ m/\s*([^;{}]*[;{}])\s*/g);

	push(@$lines, @splitted);
};

sub canonize {
	my $f = shift;
	my @lines = ();
	
	my $oneliner = '';
	
	
	while (<$f>) {
		s/(^\s+|\s+$)//g;
		s|//.*$||g; #line comment
		s/(\n|\r)//;
		
		if (m/^#/) {
			#macro	
			push(@lines, $_);
		} else {
			$oneliner .= " ".$_;
		}
		
	}
	
	$oneliner =~ s|/\*.*?\*/||g; #in-line comment 
	
	$oneliner =~ s/</ < /g; 
	$oneliner =~ s/>/ > /g; 
	$oneliner =~ s/\s+/ /g; # replace many spaces by one
	
	pushSegment($oneliner, \@lines);
	
	return @lines;
}

1;